package com.right.dao.impl;

import java.util.List;

import com.Tools.DBTools;
import com.right.dao.FoodstypeDao;
import com.right.entity.Foodstype;
import com.right.entity.Store;

public class FoodstypeDaoImpl implements FoodstypeDao {

	@Override
	public boolean addFoodsType(Foodstype foodstype) {
		if (foodstype != null) {
			String sql = "insert into foodstype values(null,?)";
			int n = DBTools.exUpdate(sql,foodstype.getTypename());
			return n > 0;
		}
		return false;
	}

	@Override
	public boolean delFoodsType(int typeid) {
		String sql = "delete from foodstype where typeid =?";
		int n = DBTools.exUpdate(sql, typeid);
		return n > 0;
	}

	@Override
	public boolean updateFoodsType(Foodstype foodstype) {
		if (foodstype != null) {
			String sql = "update foodstype set typename=? where typeid=?";
			int n = DBTools.exUpdate(sql, foodstype.getTypename(),foodstype.getTypeid());
			return n > 0;
		}
		return false;
	}

	@Override
	public List<Foodstype> getFoodsType(String keywords) {
		String sql = "select typeid,typename from foodstype where typename like ?";
		return (List<Foodstype>) DBTools.exQuery(sql, Foodstype.class, '%' + keywords + "%");
	}

	@Override
	public Foodstype getFoodsTypeByName(String typename) {
		String sql = "select typeid from foodstype where typename = ?";
		List<Foodstype> list = (List<Foodstype>) DBTools.exQuery(sql, Foodstype.class, typename);

		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}

}
